/**
**移动
**/
var moveForTr = {
	moveUp:function(tableId){
		var trArr = $("#"+tableId).find("tr");
		var nowIndex = moveForTr.getTr_index(tableId);
		var prevIndex = moveForTr.getTr_Prev_index(tableId);
		moveForTr.move(trArr,tableId, nowIndex, prevIndex);
		if(liObj != undefined && liObj != null){
			var nowId = $(trArr[nowIndex]).find('input[type="checkbox"]').val();
			var moveId = $(trArr[prevIndex]).find('input[type="checkbox"]').val();
			if(nowId != undefined && moveId != undefined)
				moveForTr.moveRequest(liObj.value, nowId, moveId);
		}
	},
	moveDown:function(tableId){
		var trArr = $("#"+tableId).find("tr");
		var nowIndex = moveForTr.getTr_index(tableId);
		var nextIndex = moveForTr.getTr_Next_index(tableId);
		moveForTr.move(trArr,tableId, nowIndex, nextIndex);
		if(liObj != undefined && liObj != null){
			var nowId = $(trArr[nowIndex]).find('input[type="checkbox"]').val();
			var moveId = $(trArr[nextIndex]).find('input[type="checkbox"]').val();
			if(nowId != undefined && moveId != undefined)
				moveForTr.moveRequest(liObj.value, nowId, moveId);
		}
	},
	moveTopBo:function(tableId,type){
		var trArr = $("#"+tableId).find("tr");
		var nowIndex = moveForTr.getTr_index(tableId);
		if(liObj != undefined && liObj != null){
			var nowId = $(trArr[nowIndex]).find('input[type="checkbox"]').val();
			if(nowId != undefined){
				moveForTr.moveTopOrBottom(nowId, liObj.value, type);
			}
		}
	},
	move:function(trArr,tableId,nowIndex,moveIndex){
		if(nowIndex != -1 && moveIndex != -1){
			var temp = trArr[nowIndex].innerHTML;
			var idtem = trArr[nowIndex].id;
			$(trArr[nowIndex]).html($(trArr[moveIndex]).html());
			$(trArr[moveIndex]).html(temp);
			$(trArr[nowIndex]).attr("id", trArr[moveIndex].id );
			$(trArr[moveIndex]).attr("id",idtem);
			$(trArr[nowIndex]).css("backgroundColor","#ffffff");
			$(trArr[moveIndex]).css("backgroundColor","#D8F79D");
			$(trArr[moveIndex]).find("input[type='checkbox']").attr('checked',true);
		}
	},
	getTr_index:function(tableId){//选中行下标
		var trIndex = -1;
		if(moveForTr.checkArticle()){
			var trObj = $("input[type='checkbox'][name='articleId']:checked").parent().parent();
			trIndex = $("#"+tableId).find("tr").index(trObj);
		}
		return trIndex;
	},
	getTr_Prev_index:function(tableId){//选中行上一行下标
		var trPrevIndex = -1;
		if(moveForTr.checkArticle()){
			var trObj = $("input[type='checkbox'][name='articleId']:checked").parent().parent().prev();
			if(trObj != undefined){
				trPrevIndex = $("#"+tableId).find("tr").index(trObj);
			}
		}
		return trPrevIndex;
	},
	getTr_Next_index:function(tableId){//选中行下一行下标
		var trPrevIndex = -1;
		if(moveForTr.checkArticle()){
			var trObj = $("input[type='checkbox'][name='articleId']:checked").parent().parent().next();
			if(trObj != undefined){
				trPrevIndex = $("#"+tableId).find("tr").index(trObj);
			}
		}
		return trPrevIndex;
	},
	checkArticle:function(){
		var check = false;
		var size = $("input[type='checkbox'][name='articleId']:checked").size();
		if(size == 1){
			check = true;
		}else{
			$.growlUI("请选中一篇文章");
		}
		return check;
	},
	moveRequest:function(tid,nowid,moveid){
		$.ajax({
			url:'orderArticleSource',
			type:'post',
			dataType:'json',
			data:{'tcolid':tid,'nowArticleId':nowid,'moveArticleId':moveid},
			success:function(data){
				if(data > 0){
					$.growlUI('已移动');
				}else{
					$.growlUI('移动失败');
				}
			},
			error:function(msg){
				$.growlUI('移动出错');
			}
		});
	},
	moveTopOrBottom:function(aid,tid,type){
		$.ajax({
			url:'moveToOrmoveBottom',
			type:'post',
			dataType:'json',
			data:{'moveArticleId':aid,'tcolId':tid,'type':type},
			success:function(data){
				if(data > 0){
					var ms = '';
					if(type == 0) ms = "已置顶";
					if(type == 1) ms = "已置尾";
					$.growlUI(ms);
					queryTcolSource(1);
				}else{
					$.growlUI('移动失败');
				}
			},
			error:function(msg){
				$.growlUI('移动出错');
			}
		});
	}
};
///排列顺序
function changeOrderType(){
	var type = $("#order_type").val();
	if(type == "insertList"){
		$("#insertList_img").show();
		$("#orderList_img").hide();
	}else{
		$("#insertList_img").hide();
		$("#orderList_img").show();
	}
	if(liObj != undefined && liObj != null){
		$.ajax({
			url:'changeOrderType',
			type:'post',
			dataType:'json',
			data:{'id':liObj.value,'forderway':type},
			success:function(data){
				if(data > 0){
					$.growlUI('排序方式已更改');
					queryTcolSource(1);
				}else{
					$.growlUI('更改失败');
				}
			},
			error:function(msg){
				$.growlUI('更改排列方式出错');
			}
		});
	}else{
		$.growlUI('请首先选择栏目');
	}
}
